package com.baizan.daka.ui.adapter


import android.graphics.Color
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.baizan.daka.mvp.model.bean.PackageBean
import com.baizan.daka.ui.activity.PayActivity
import com.baizan.daka.util.HyperTextUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.dianzan.daka.R

class PackageAdapter(val type: Int? = 0) :
    BaseQuickAdapter<PackageBean, BaseViewHolder>(R.layout.item_package) {


    override fun convert(helper: BaseViewHolder, item: PackageBean) {
        helper.setText(R.id.vip_name_tv, item.packageName)
            .setText(
                R.id.like_sum_tv, HyperTextUtil.build("获赞数：")
                    .appendColor("${item.likeNumber}", Color.parseColor("#1B78FD"))
                    .Builder()
            )
            .setText(
                R.id.reward_price_tv, HyperTextUtil.build("悬赏金额：")
                    .appendColor("${item.unitPrice}", Color.parseColor("#1B78FD"))
                    .Builder()
            )
            .setText(
                R.id.vip_prcie_tv, HyperTextUtil.build(item.packagePrice)
                    .appendSize("元", 12).Builder()
            )
            .setText(R.id.task_sum_tv, "${item.packageDesc}")
        if (type == 0) {
            helper.getView<TextView>(R.id.submit_bt)
                .setOnClickListener {
                    PayActivity.startPayPackage(mContext, item)
                }
            helper.setVisible(R.id.package_number, false)
        } else {
            helper.setVisible(R.id.package_number, true)
            helper.getView<TextView>(R.id.submit_bt).visibility = View.GONE
        }
       val line = helper.getView<View>(R.id.bg_line)
        val nameTv = helper.getView<TextView>(R.id.vip_name_tv)
        when (item.packageLevel) {
            1 -> {
                line.setBackgroundResource(R.drawable.shape_task_level_1)
                nameTv.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_1)
                    , null, null, null
                )
            }
            2 -> {
                line.setBackgroundResource(R.drawable.shape_task_level_2)
                nameTv.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_2)
                    , null, null, null
                )
            }
            3 -> {
                line.setBackgroundResource(R.drawable.shape_task_level_3)
                nameTv.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_3)
                    , null, null, null
                )
            }
            4 -> {
                line.setBackgroundResource(R.drawable.shape_task_level_4)
                nameTv.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_4)
                    , null, null, null
                )
            }
        }
    }


}